<?php
/**
 * File: Upload.php
 * User: Mr.Yang
 * Date: 2025/3/19 0019
 * Time: 15:10
 * Note:
 */

namespace app\common\controller;


use think\Controller;

class Upload extends Controller
{
    public function index()
    {
        $file = request()->file('file');
        if ($file) {
            $dir = './uploads';
            // 移动到框架应用根目录/uploads/ 目录下
            $info = $file->move($dir);
            if($info){
                $filename = str_replace('\\', '/', $info->getSaveName());
                return json(['code' => 0,'url' => trim($dir, '.').'/'.$filename]);
            }else{
                // 上传失败获取错误信息
                return json(['code' => 1,'msg' => $file->getError()]);
            }
        }

    }
}